package service.serviceImpl;

import dao.ReservationMapper;
import entity.Reservation;
import entity.example.ReservationExample;
import net.sf.jsqlparser.statement.execute.Execute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.ReservationService;

import java.util.List;

/***
 * Author: Mr.Zhao, Time: 2019/5/23/17:04
 * Description:
 */
@Service
public class ReservationServiceImpl implements ReservationService {
    @Autowired
    ReservationMapper reservationDao;

    /**
     * 根据用户名查询预约记录，按照预约开始时间降序排列
     *
     * @param username 用户名
     * @return
     */
    public List<Reservation> selectByUsername(String username) {
//        ReservationExample reservationExample = new ReservationExample();
//        ReservationExample.Criteria criteria = reservationExample.createCriteria();
//        reservationExample.setOrderByClause("time desc");
//        criteria.andUsernameEqualTo(username);
//
//
//        return reservationDao.selectByExample(reservationExample);
        return reservationDao.selectByUsername(username);
    }

    @Override
    public int addReservation(Reservation reservation) throws Exception {
        return reservationDao.insert(reservation);
    }

    @Override
    public List<Reservation> selectNotAuditedReservation() throws Exception {
        return reservationDao.selectNotAuditedReservation();
    }

    @Override
    public List<Reservation> selectAuditedReservation() throws Exception {
        return reservationDao.selectAuditedReservation();
    }

    @Override
    public void update(Reservation reservation) throws Exception {
        reservationDao.updateByPrimaryKeySelective(reservation);
    }

    @Override
    public List<Reservation> selectByClassroomId(Integer classroomId) throws Exception {
        ReservationExample reservationExample = new ReservationExample();
        ReservationExample.Criteria criteria = reservationExample.createCriteria();
        criteria.andClassroom_idEqualTo(classroomId);
        return reservationDao.selectByExample(reservationExample);
    }
}
